package han.chensing.latos.res;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;

import han.chensing.latos.game.util.TextureUtil;

public abstract class LoadEntry {
    public enum Type{
        Texture,TextureRegion,Sound,TTFGenerator,TTF,Animation
    }
    public Type type;
    public String name;

    public abstract Object realLoad(Res res);

    public LoadEntry(Type type, String name){
        this.type=type;
        this.name=name;
    }

    public static class TextureEntry extends LoadEntry {
        private final String path;
        public TextureEntry(String name,String path) {
            super(Type.Texture,name);
            this.path=path;
        }
        @Override
        public Object realLoad(Res res) {
            return new Texture(path);
        }
    }

    public static class TextureRegionEntry extends LoadEntry {
        private final String textureName;
        public TextureRegionEntry(String name,String textureName) {
            super(Type.TextureRegion, name);
            this.textureName=textureName;
        }
        @Override
        public Object realLoad(Res res) {
            return new TextureRegion(res.get(textureName, Texture.class));
        }
    }

    public static class SoundRegionEntry extends LoadEntry{
        private final String path;
        public SoundRegionEntry(String name,String path){
            super(Type.Sound,name);
            this.path=path;
        }
        @Override
        public Object realLoad(Res res) {
            return Gdx.audio.newSound(Gdx.files.internal(path));
        }
    }

    public static class AnimationEntry extends LoadEntry{
        private final int width;
        private final int height;
        private final String texturePath;
        public AnimationEntry(String name, String texturePath, int width, int height) {
            super(Type.Animation, name);
            this.width = width;
            this.height = height;
            this.texturePath = texturePath;
        }
        @Override
        public Object realLoad(Res res) {
            return TextureUtil.genAnimationWithTexture(
                    res.get(texturePath, Texture.class),width,height);
        }
    }

    public static class TTFGeneratorEntry extends LoadEntry{
        private final String path;
        public TTFGeneratorEntry(String name, String path) {
            super(Type.TTFGenerator, name);
            this.path = path;
        }
        @Override
        public Object realLoad(Res res) {
            return new FreeTypeFontGenerator(Gdx.files.internal(path));
        }
    }

    public static class TTFEntry extends LoadEntry{
        private final String generatorName;
        private final int size;
        public TTFEntry(String name, String generatorName, int size) {
            super(Type.TTF, name);
            this.generatorName=generatorName;
            this.size = size;
        }
        @Override
        public Object realLoad(Res res) {
            FreeTypeFontGenerator.FreeTypeFontParameter freeTypeFontParameter=new FreeTypeFontGenerator.FreeTypeFontParameter();
            freeTypeFontParameter.characters=FreeTypeFontGenerator.DEFAULT_CHARS;
            freeTypeFontParameter.color= Color.WHITE;
            freeTypeFontParameter.size=size;
            //freeTypeFontParameter.gamma=0.8f;
            return res.get(generatorName, FreeTypeFontGenerator.class).generateFont(freeTypeFontParameter);
        }
    }
}
